#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
int a[N], sum[N];
vector<int> get(int x) {
  vector<int> res;
  // without the last num
  rep(i, 1, n - 1) if (sum[i] == x) res.push_back(i);
  return res;
}
void solve() {
  cin >> n;
  rep(i, 1, n) cin >> a[i];
  rep(i, 1, n) sum[i] = sum[i - 1] + a[i];
  if (sum[n] % 3) {
    cout << 0;
    return;
  }
  vector<int> b = get(sum[n] / 3);
  vector<int> c = get(sum[n] / 3 * 2);
  ll ans = 0;
  for (int i : b) {
    int cnt = c.end() - upper_bound(c.begin(), c.end(), i);
    ans += cnt;
  }
  cout << ans;
  return;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  t = 1;
  while (t--) solve();
  return 0;
}